package auth

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"
	v1 "gitee.com/liuxuezhan/ar-platform/rpc-client/authRoleClient/api/role/v1"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetMenuInfoLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 获取菜单详情
func NewGetMenuInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetMenuInfoLogic {
	return &GetMenuInfoLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetMenuInfoLogic) GetMenuInfo(req *types.GetMenuInfoRequest) (resp *types.GetMenuInfoResponse, err error) {
	reply, err := l.svcCtx.AuthRoleRpc.GetMenuInfo(l.ctx, &v1.GetMenuInfoRequest{Id: req.Id})
	if err != nil {
		return nil, err
	}

	return &types.GetMenuInfoResponse{
		Id:           reply.Id,
		MenuPid:      reply.MenuPid,
		MenuName:     reply.MenuName,
		MenuType:     int8(reply.MenuType),
		Target:       int8(reply.Target),
		Url:          reply.Url,
		Icon:         reply.Icon,
		ListOrder:    reply.ListOrder,
		Remark:       reply.Remark,
		Status:       int8(reply.Status),
		Identifier:   reply.Identifier,
		Visible:      int8(reply.Visible),
		Refresh:      int8(reply.Refresh),
		CreatedAt:    reply.CreatedAt,
		UpdatedAt:    reply.UpdatedAt,
		MenuLanguage: reply.MenuLanguage,
	}, err
}
